#
# @lc app=leetcode.cn id=376 lang=python
#
# [376] 摆动序列
#

# @lc code=start
class Solution(object):
    def wiggleMaxLength(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        if len(nums) < 2:
            return len(nums)
        
        cur_diff = 0
        pre_diff = 0
        result = 0
        for i in range(len(nums)-1):
            cur_diff = nums[i+1] - nums[i]
            if (pre_diff>=0 and cur_diff<0) or (pre_diff<=0 and cur_diff>0):
                result += 1
                pre_diff = cur_diff
        return result+1
        
# @lc code=end

